package com.mio.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.durcframework.core.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.mio.web.entity.product.Product;
import com.mio.web.entity.sys.SysUpload;
import com.mio.web.service.log.SysLogService;
import com.mio.web.service.message.MessageService;
import com.mio.web.service.moive.MovieService;
import com.mio.web.service.product.ProductService;
import com.mio.web.service.recommend.RecommandService;
import com.mio.web.service.sys.SysUploadService;

/**
 * 首页中的controller
 * 
 * @author gushenjie
 *
 */
@Controller
public class IndexCtrl {
	@Autowired
	MovieService movieService;
	@Autowired
	ProductService productService;
	@Autowired
	RecommandService recommandService;
	@Autowired
	MessageService messageService;
	@Autowired
	SysUploadService sysUploadService;
	@Autowired
	SysLogService sysLogService;

	@RequestMapping(value = "index.do")
	public ModelAndView getIndexData(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("/index.jsp");
		view.addObject("loginUser", UserContext.getInstance().getUser());
		// 获取视频对象
		view.addObject("movie", movieService.getIndexMoive());
		// 5个热销产品
		view.addObject("productList", productService.listIndexProduct());
		// 3个美美推荐
		view.addObject("recommendList", recommandService.listIndexRecommend());
		// 5条最新的消息
		view.addObject("messageList", messageService.listIndexMessage());
		// 二维码上方1条产品信息
		SysUpload upProduct = sysUploadService.getFirstSysUploadByFuncId("codeUpProduct");
		Product codeUpProduct = productService.get(upProduct.getZipId());
		if(codeUpProduct != null){
			codeUpProduct.setSImgUrl(upProduct.getFileFullPath());
		}
		view.addObject("codeUpProduct",codeUpProduct);
		//二维码左侧2条产品信息
		view.addObject("codeLeftProduct",sysUploadService.getNumsSysUploadByFuncId("codeLeftProduct",2));
		
		return view;

	}

	@RequestMapping(value = "aboutUs.do")
	public ModelAndView getAboutUs(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("/aboutUs.jsp");
		view.addObject("loginUser", UserContext.getInstance().getUser());
		return view;

	}
}
